package com.lz.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lz.gmall.common.result.Result;
import com.lz.gmall.common.result.ResultCodeEnum;
import com.lz.gmall.product.entity.SpuInfo;
import com.lz.gmall.product.dto.SpuInfoDto;
import com.lz.gmall.product.service.SpuInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product")
@Api("产品spu操作")
public class SpuInfoController {

    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * 获取产品spu的详细信息，必须是三级产品
     * @param pageNum 页码
     * @param limit 每页条数
     * @param c3Id 三级产品id
     * @return 分页集合
     */
    @GetMapping("{page}/{limit}")
    @ApiOperation("分页spu详细信息")
    public Result<Page<SpuInfo>> getSpuInfoPage(@PathVariable("page") Integer pageNum,
                                                @PathVariable("limit") Integer limit,
                                                @RequestParam("category3Id")Long c3Id){
        Page<SpuInfo> page = spuInfoService.getSpuInfoPage(pageNum, limit, c3Id);
        return Result.build(page, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加spu
     * @param spuInfoDto spu产品的封装信息
     * @return
     */
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfoDto spuInfoDto){
        spuInfoService.saveSpuInfo(spuInfoDto);
        return Result.ok();
    }
}
